// 导航栏选项卡
var arr = ['001','002','003','004','005','006','007',]
var oBar = document.querySelectorAll('.bar-xiali');
// console.log(oBar);
for(var i = 0; i < arr.length; i++){
    oBar[i].setAttribute('type',arr[i])
}
// let typeId = sum
function getGoods(){
    $.get(`../php/phpe/getGoodsListNew.php?typeId=006&count=8`,function(data){
        let goodlist = JSON.parse(data);
        // console.log(data);
        let htmlSrc = ''
        goodlist.forEach( goods=> {
            htmlSrc+=`
            <li class="bar-li">
            <img src="../${goods.goodsImg}">
            <div class="bar-ming">${goods.goodsName}</div>
            <p class="bar-jia">${goods.goodsPrice}元起</p>
            </li>
            <li class="bar-li2"></li>
            `
        });
        $('.bar-ul').html(htmlSrc)
    })
}
// 导航栏
var sum = '';
$('.bar-xiali').hover(function(){
    var num = this.getAttribute('type');
    sum = num
    $('.bar-xuan').css({
        'display':'block'
    })
},function(){
    $('.bar-xuan').hover(function(){
        $('.bar-xuan').css({
            'display':'block'
        })
    },function(){
        $('.bar-xuan').css({
                'display':'none'
            })
    })
})
$(function(){
        getGoods()
})

// 轮播图上的nav的选项卡
// var str = ['010','011','012','013','014','015','016','017','018','019',]
// var oItem = document.querySelectorAll('.category_item')
// for (var i = 0; i < str.length; i++) {
//     oItem[i].setAttribute('type',ser[i])
// }
function getXuan(){
    $.get("../php/phpe/getGoodsListNew.php?typeId=006&count=8",function(data){
        let goodlist = JSON.parse(data);
        // console.log(goodlist);
        let htmlSrc = ''
        goodlist.forEach(goods=>{
            htmlSrc+=`
            <li class="item-li">
            <img src="../${goods.goodsImg}">
            <span class="item-span">${goods.goodsName}</span>
            </li>
            `
        })
        $('.item-ul').html(htmlSrc)

    })
}
$(function(){
    getXuan()
})

// 轮播图上的nav
$('.category_item').hover(function(){
    $(this).css('background','#ff6700')
    $('.item-div').eq($(this).index()).css({
        'visibility':'visible'
    })
    $('.view').css({
        display:'none'
    })
},function(){
    $(this).css('background','')
    $('.item-div').eq($(this).index()).css({
        'visibility':'hidden'
    })
    $('.view').css({
        display:'block'
    })
})
// 轮播图
var zindex = 0;
$('.dot .dot-li').on('click',function(){
    $(this).addClass('dot-oli').siblings('.dot-li').removeClass('dot-oli');
    var index = $(this).index()
    zindex = index;
    auto(index)
})
function auto(index){
    $('.map .map-li').eq(index).fadeIn(500).siblings('.map-li').fadeOut(500)
}
$('.view-sp1').on('click',function(){
    if(zindex<=0){
        zindex=5
    }
    zindex--
    auto(zindex);
    $('.dot .dot-li').eq(zindex).addClass('dot-oli').siblings('.dot-li').removeClass('dot-oli');
})
$('.view-sp2').on('click',function(){
    if(zindex>=4){
        zindex=-1
    }
    zindex++
    auto(zindex);
    $('.dot .dot-li').eq(zindex).addClass('dot-oli').siblings('.dot-li').removeClass('dot-oli');
})
function teamer(){
    timer=setInterval(function(){
        $('.view .view-sp2').trigger('click')
    },3000)
}
teamer()
$('.slideshow').hover(function(){
    clearInterval(timer)
},function(){
    teamer()
})
// 回到顶部
$(window).on('scroll',function(){
    if ($(window).scrollTop()<=800) {
        $('.home-tool').css({
            bottom:'-32px'
        })
        $('.home-din').css({
            'visibility':'hidden'
        })
    }else{
        $('.home-tool').css({
            bottom:'70px'
        })
        $('.home-din').css({
            'visibility':'visible'
        })
    }
})
$('.home-din').on('click',function(){
    $('html,body').animate({
        scrollTop:0
    },10)
})

// 下载APP
$('.site').hover(function(){
    $('.left_xia').slideDown()
},function(){
    $('.left_xia').slideUp()
})
// 跳转登录
$('.topbanden').on('click',function(){
    location.href = 'denlu.html'
})
// 跳转注册
$('.topbanzhu').on('click',function(){
    location.href = 'zhuce.html'
})
// 跳转到购物车
$('.topbanright1').on('click',function(){
    location.href = 'shopping.html'
})
$('.shopps').on('click',function(){
    location.href = 'shopping.html'
})

// 商品页一接口
function getcommod(){
    $.get("../php/phpe/getGoodsListNew.php?typeId=006&count=8",function(data){
        let goodlist = JSON.parse(data);
        // console.log(goodlist);
        let htmlSrc = ''
        goodlist.forEach(goods=>{
            htmlSrc+=`
            <li class="ping-li" onclick="location.href = 'xiangqin.html?goodsId=${goods.goodsId}'">
            <div class="ping-zhong">
                <img src="../${goods.goodsImg}">
                <p class="ping-sp1">${goods.goodsName}</p>
                <p class="ping-sp2">${goods.goodsDesc}</p>
                <p class="ping-sp3"><span class="ping-num">${goods.goodsPrice}</span>元起</p>
            </div>
        </li>
            `
        })
        $('.ping-ul').html(htmlSrc)
    })
}
$(function(){
    getcommod()
})
// 商品页二接口
function gethome(){
    $.get("../php/phpe/getGoodsList.php?typeId=006&count=8",function(data){
        let goodlist = JSON.parse(data);
        // console.log(goodlist);
        let htmlSrc = ''
        goodlist.forEach(goods=>{
            htmlSrc+=`
            <li class="erte-li2" onclick="location.href = 'xiangqin.html?goodsId=${goods.goodsId}'">
                        <div class="erte-zhong">
                            <img src="../${goods.goodsImg}">
                            <p class="erte-sp1">${goods.goodsName}</p>
                            <p class="erte-sp2">${goods.goodsDesc}</p>
                            <p class="erte-sp3"><span class="erte-num">${goods.goodsPrice}</span>元起</p>
                        </div>
                    </li>
            `
        })
        $('.erte-ul').html(htmlSrc)
    })
}
$(function(){
    gethome()
})

// 登录后的用户名显示
function denluming(){
    if(getCookie('username')=='') {
        $('.topbanright2').css('display','block')
        $('.topbanright3').css('display','none')
    }else{
        $('.topbanright2').css('display','none')
        $('.topbanright3').css('display','block')
        $('.user-left .user-min').html(getCookie('username'))
    }
}
$(function(){
    denluming()
})
// 退出登录
$('#user_tuchu').on('click',function(){
    delCookie('username');
    denluming()
})
